import { create } from 'zustand';

interface State {
  /**
   * 当前选中的 tab 索引
   */
  currentIndex: number;
}

const initialState: State = {
  currentIndex: 0,
};

interface Actions {
  /**
   * 设置当前选中的 tab 索引
   * @param index
   * @returns
   */
  setCurrentIndex: (index: number) => void;
}

export const useTabBarStore = create<State & Actions>((set) => ({
  ...initialState,
  setCurrentIndex: (index: number) => {
    set({ currentIndex: index });
  },
}));
